package com.leetcode.dynamic_programming;

/**
 * @author Dennis Li
 * @date 2020/7/19 16:06
 */
public class NumberOfArithmeticSlices_413 {

    public int numberOfArithmeticSlices(int[] A) {
        if (A.length < 3) return 0;
        int len = A.length, sum = 0;
        // 状态方程为以i结尾的等差数列的个数
        int[] dp = new int[len];
        for (int i = 2; i < len; i++) {
            if (A[i] - A[i - 1] == A[i - 1] - A[i - 2]) {
                // 如果满足等差数列的条件，那么就在原来的基础上+1
                // 否则置为0
                dp[i] = dp[i - 1] + 1;
                sum += dp[i];
            }
        }
        return sum;
    }

}
